//
//  WhereToBuyViewController.m
//  AirConditioner
//
//  Created by Sean Wang on 12-4-24.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "WhereToBuyViewController.h"
#import "BrandBottomViewController.h"
#import "CustomerCareViewController.h"
#import "FindSitesViewController.h"

@interface WhereToBuyViewController ()

@end

@implementation WhereToBuyViewController

@synthesize findSitesViewController;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"Where to Buy";
        self.tabBarItem.image = [UIImage imageNamed:@"103-map"];
        
        UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init];
        temporaryBarButtonItem.title = @"Back";
        self.navigationItem.backBarButtonItem = temporaryBarButtonItem;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    //CGRect frame = CGRectMake(0, 330, 320, 37);
    UIViewController *viewController = [[BrandBottomViewController alloc] initWithNibName:@"BrandBottomView" bundle:nil];
    //bottomView = viewController.view;
    //bottomView.frame = frame;
    //UIColor *a = [UIColor grayColor];
    //NSLog(@"",viewController.view.backgroundColor.)
    [self.view addSubview:viewController.view];
    
}

- (IBAction)buttonClicked:(id)sender
{
    UIButton *button = (UIButton*)sender;
    switch (button.tag) {
        case 1:
            [self navigateToFindSitesPage:1];
            break;
        case 2:
            [self navigateToFindSitesPage:2];
            break;
        case 3:
            if(customerCareViewController == nil){
                customerCareViewController = [[CustomerCareViewController alloc]
                                              initWithNibName:@"CustomerCareViewController" bundle:nil];
            }
            [[self navigationController] pushViewController:customerCareViewController animated:YES];
            break;
        default:
            break;
    }
}

- (void) navigateToFindSitesPage: (NSInteger)state
{
    if(self.findSitesViewController == nil){
        self.findSitesViewController = [[FindSitesViewController alloc]
                                      initWithNibName:@"FindSitesViewController" bundle:nil];
    }
    self.findSitesViewController.currentState = state;
    self.findSitesViewController.postcodeField.text = @"";
    self.findSitesViewController.suburbField.text = @"";
    [[self navigationController] pushViewController:self.findSitesViewController animated:YES];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
